import time 
import threading
from concurrent.futures import ThreadPoolExecutor

def work(*args):
    name = threading.current_thread().name
    print(f"Starting {name}")
    count = args[0]
    intv = args[1]
    work = args[2]

    for i in range(count):
        print(f"{name} Working {work} {i}")
        time.sleep(intv)

# 创建线程池(最大线程为20)
# thread_name_prefix: 线程名称前缀
executor = ThreadPoolExecutor(max_workers=20, thread_name_prefix='my_thread')

# 提交任务
# 1. 要执行的任务函数（必须是可调用对象）
# 2. 任务次数（整数类型，表示循环执行次数）
# 3. 间隔时间（整数/浮点数，单位：秒）
# 4. 任务描述（字符串类型，用于输出标识）
executor.submit(work, 5, 1, 'singing...')
executor.submit(work, 10, 2, 'dancing...')
executor.submit(work, 3, 3, 'sleeping...')

executor.shutdown()
